home *** CD-ROM | disk | FTP | other *** search
- Path: doc.ic.ac.uk!usenet
- From: Ben Jefferys <brj@doc.ic.ac.uk>
- Newsgroups: comp.lang.c++
- Subject: Saving a C++ object
- Date: Thu, 29 Feb 1996 15:33:34 +0000
- Organization: Imperial College, Computing Department
- Message-ID: <3135C74E.446B9B3D@doc.ic.ac.uk>
- NNTP-Posting-Host: oak44.doc.ic.ac.uk
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; SunOS 4.1.3_U1 sun4c)
-
- When I save a C++ object just using:
-
- ----------------------------
- class ovoid{
- /* etc. */
- }
-
- ovoid square
-
- file.write((unsigned char *) &square, sizeof(ovoid))
- ----------------------------
-
- What *exactly* is saved? I'm finding that every time I recompile
- an application when I've added some new code, trying to load
- an object saved in this way with an old version of the application
- crashes it, even if the class of the object in question hasn't
- changed. I presume there are some pointers or something which are
- changing when I add new chunks of code. What can I do to avoid this?
-
- (ovoid doesn't containg any explicit pointers which are not reset when
- reloading - ie. I'm not trying to use old pointers which have
- been saved - not to my knowledge anyway)
-
- Also, is there anything dodgy about saving a class from within itself,
- using:
-
- file.write((unsigned char *) &this, sizeof(ovoid))
-
- Thanks for your help.
-
- --
- Je suis triste et seul ici.
-